<template>
  <div class="order-assign">
    <el-form :inline="true" size="mini" style="margin-left: 10px" class="search-form">
      <el-form-item label="客户电话">
        <el-input v-model="search.customerPhone"></el-input>
      </el-form-item>
      <el-form-item label="业务员电话">
        <el-input v-model="search.employeePhone"></el-input>
      </el-form-item>
      <el-form-item label="类型">
        <el-select v-model="search.status" placeholder="请选择">
          <el-option
            :key="ASSIGN_STATUS.DONE.val"
            :label="ASSIGN_STATUS.DONE.name"
            :value="ASSIGN_STATUS.DONE.val"
          ></el-option>
          <el-option
            :key="ASSIGN_STATUS.PENDING.val"
            :label="ASSIGN_STATUS.PENDING.name"
            :value="ASSIGN_STATUS.PENDING.val"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-plus" @click="mSearch()">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="orderList" size="mini" :height="getTableHeight(150)">
      <el-table-column prop="orderId" label="订单号" width="250"></el-table-column>
      <el-table-column prop="customerName" label="客户"></el-table-column>
      <el-table-column prop="customerTel" label="客户电话"></el-table-column>
      <el-table-column prop="empName" label="业务员"></el-table-column>
      <el-table-column prop="empTel" label="业务员电话"></el-table-column>
      <el-table-column prop="prodName" label="产品" width="340"></el-table-column>
      <el-table-column prop="orderDate" label="创建时间" width="140"></el-table-column>
      <el-table-column label="第几次校验" width="140">
        <template slot-scope="scope">{{`第${scope.row.applyStatus2Times.DONE}次`}}</template>
      </el-table-column>
      <el-table-column label="季度付费" width="100">
        <template slot-scope="scope">{{scope.row.creditStrategy==='SEASON'?'是':'否'}}</template>
      </el-table-column>
      <el-table-column label="操作" v-if="search.status===ASSIGN_STATUS.PENDING.val">
        <template slot-scope="scope">
          <a class="t-link" @click="toPassCheck(scope.row,true)">通过</a>
          <a class="t-link" @click="toPassCheck(scope.row,false)">拒绝</a>
        </template>
      </el-table-column>
    </el-table>
    <div class="paging-block" style="text-align: center">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pagination.pageNum"
        :page-sizes="[15, 20, 30, 40]"
        :page-size="pagination.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pagination.total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import * as orderApi from "@/api/order_manage";
import orderMixin from "@/views/order-manage/order_mixin";
import ajax from "@/api/ajax";
export default {
  name: "order-check",
  mixins: [orderMixin],
  data: function() {
    let ASSIGN_STATUS = {
      PENDING: { name: "待检验", val: "CHECKING" },
      DONE: { name: "已完成", val: "CHECKED" }
    };
    return {
      assignAdminDialogVisible: false,
      admins: [],
      selectedOrer: null,
      selectedAdmin: null,
      search: {
        adminName: "",
        status: ASSIGN_STATUS.PENDING.val
      },
      fil: {
        adminName: "",
        phone: ""
      },
      pagination: {
        limit: 15, // 每页数据大小
        pageNum: 1, // 当前页数
        total: 0 // 全部数据条数
      },
      ASSIGN_STATUS: ASSIGN_STATUS
    };
  },
  methods: {
    mSearch() {
      let params = Object.assign({}, this.pagination, this.search);
      this.searchOrder(params).then(result => {
        console.log(result);
      });
    },
    handleCurrentChange(currentPage) {
      this.pagination.pageNum = currentPage;
      this.mSearch();
    },
    handleSizeChange(size) {
      this.pagination.limit = size;
      this.mSearch();
    },
    toPassCheck(order, pass) {
      this.$swal({
        title: pass ? `请确定让该订单通过检验？` : `确定要拒绝通过订单检验吗？`,
        input: "textarea",
        inputPlaceholder: "请输入备注",
        showCancelButton: true,
        showCloseButton: true
      }).then(result => {
        debugger;
        if (!result) return;
        if (result && result.dismiss) return;
        let remark = result.value;
        let status = pass ? "DONE" : "REFUSE";
        let orderCheckItems = order.orderCheckItems;
        let checkId = orderCheckItems.filter(
          item => item.checkStatus === "PENDING"
        )[0].checkId;
        let url = `/api/sys/order/check/${checkId}`;
        ajax.put(url, { remark, status: status }).then(resp => {
          let result = resp.data;
          this.handleOpSuccess(result);
          this.mSearch();
        });
      });
    },
    showAll() {
      this.fil.adminName = "";
      this.fil.phone = "";
    }
  },
  created() {
    this.mSearch();
  },
  filters: {
    filterAdmin(admins, adminFilter) {
      return admins.filter(admin => {
        let rt = true;
        if (adminFilter.adminName) {
          rt = admin.name.indexOf(adminFilter.adminName) !== -1;
        }
        if (adminFilter.phone) {
          rt = admin.phone.indexOf(adminFilter.phone) !== -1;
        }
        return rt;
      });
    }
  }
};
</script>
<style>
</style>


